/** Sopaco - (c) Sopaco Advanced Technique Support */
import { __assign, __extends } from 'tslib';
import * as tslib_1 from 'tslib';
import React, { Component } from 'react';
import { Provider } from 'mobx-react';
import { Schedule } from 'react-apm-api';
import { ConsoleOutlet, MemoryRecorder, Profiler } from 'react-apm-core';
import { BootPlugin, CpuPlugin, FpsPlugin, GcpPlugin, JSEventLoopPlugin, MemoryPlugin, MethodTracePlugin, MrtPlugin, ScuPlugin, TrafficPlugin } from 'react-apm-plugins';

function assemble(Comp, contextCreator, convert) {
    return /** @class */ (function (_super) {
        __extends(MobxComponent, _super);
        function MobxComponent(props) {
            var _this = _super.call(this, props) || this;
            _this.state = { params: null };
            var params = convert ? convert(props) : props.params;
            _this.contexture = contextCreator(params);
            return _this;
        }
        MobxComponent.getDerivedStateFromProps = function (nextProps, prevState) {
            var params = convert ? convert(nextProps) : {};
            return { params: params };
        };
        MobxComponent.prototype.render = function () {
            var _a = this, contexture = _a.contexture, state = _a.state;
            return (React.createElement(Provider, { context: contexture },
                React.createElement(Comp, __assign({}, this.props, { context: contexture, params: state.params }))));
        };
        MobxComponent.prototype.componentDidMount = function () {
            var contexture = this.contexture;
            return contexture.componentDidMount && contexture.componentDidMount();
        };
        MobxComponent.prototype.getSnapshotBeforeUpdate = function (prevProps, prevState) {
            var contexture = this.contexture;
            return contexture.getSnapshotBeforeUpdate && contexture.getSnapshotBeforeUpdate(prevProps, prevState);
        };
        MobxComponent.prototype.componentDidUpdate = function () {
            var contexture = this.contexture;
            return contexture.componentDidUpdate && contexture.componentDidUpdate();
        };
        MobxComponent.prototype.componentWillUnmount = function () {
            var contexture = this.contexture;
            return contexture.componentWillUnmount && contexture.componentWillUnmount();
        };
        MobxComponent.prototype.componentDidCatch = function (error, info) {
            var contexture = this.contexture;
            return contexture.componentDidCatch && contexture.componentDidCatch(error, info);
        };
        return MobxComponent;
    }(Component));
}

var Context = /** @class */ (function () {
    function Context(props) {
        this.props = props;
    }
    return Context;
}());



var index = Object.freeze({
	assemble: assemble,
	Context: Context
});

function launchDefaults() {
    return Promise.all([
        CpuPlugin,
        FpsPlugin,
        GcpPlugin,
        MemoryPlugin,
        MrtPlugin,
        TrafficPlugin,
        ScuPlugin,
        BootPlugin,
        JSEventLoopPlugin,
        MethodTracePlugin
    ].map(function (PluginType) {
        var plugin = new PluginType();
        var recorder = new MemoryRecorder();
        var outlet = new ConsoleOutlet();
        var profiler = new Profiler(plugin, recorder, outlet);
        return profiler.start({ boot: Schedule.Erupt, sampler: {} });
    }));
}


var index$1 = Object.freeze({
	launchDefaults: launchDefaults
});

export { index as mobx, index$1 as performance };
